﻿using System;
using System.Collections.Generic;
using System.Text;
using Mono.Cecil;
using Mono.Cecil.Cil;

namespace LibParasInject
{
    static class ExtensionILProcessor
    {
        public static Instruction createLdargX(this ILProcessor worker, int paramIndex)
        {
            if (paramIndex == 0)
                return worker.Create(OpCodes.Ldarg_0);

            if (paramIndex == 1)
                return worker.Create(OpCodes.Ldarg_1);

            if (paramIndex == 2)
                return worker.Create(OpCodes.Ldarg_2);

            if (paramIndex == 3)
                return worker.Create(OpCodes.Ldarg_3);

            if ((paramIndex >= 4) && (paramIndex <= 255))
                return worker.Create(OpCodes.Ldarg_S, (byte)paramIndex);

            return worker.Create(OpCodes.Ldarg, paramIndex);
        }
    }
}
